#include "Sqlist-Define.h"



int DeleteMin(SqList &L, int &e)
{
    if (L.length == 0)  // sqlist is NULL
    {
        puts("Error: the Sqlist is Null.");
        return 0;
    }

    //get Minist Elem
    int pos=0, min_e=L.data[0]; 
    for(int i=1; i<L.length; i++)
    {
        if(L.data[i] < min_e)
        {
            min_e = L.data[i];
            pos = i;
        }
    }

    e = L.data[pos];
    L.data[pos] = L.data[L.length-1];  // 把最后一个元素填入空出的位置

    return e;

}


int main()
{
    SqList L;
    L.length = 0;
    ListInsert(L, 1, 10);
    ListInsert(L, 2, 8);
    ListInsert(L, 3, 6);
    ListInsert(L, 4, 40);
    ListInsert(L, 5, 25);
    PrintList(L);


    int e, e_min;
    e_min = DeleteMin(L, e);

    printf("%d is the minist elem.", e_min);
    PrintList(L);

    return 0;
}